package mygame;

import com.jme3.scene.Node;
import gameobject.construct.GrassBlock;

public abstract class WorldCreator {

    public static Node createChunk(Vector3i minLocation, Vector3i maxLocation) {
	Node chunk = new Node("chunk");
	Vector3i currentMin;
	Vector3i currentMax;
	for (int i=minLocation.getY(); i<=maxLocation.getY(); i++) {
	    currentMin = new Vector3i(minLocation.getX(), i, minLocation.getZ());
	    currentMax = new Vector3i(maxLocation.getX(), i, maxLocation.getZ());
	    Node yLayer = createSingleYLayer(currentMin, currentMax);
	    chunk.attachChild(yLayer);
	}
	return chunk;
    }

    public static Node createSingleYLayer(Vector3i minLocation, Vector3i maxLocation) {
	Node yLayer = new Node("yLayer");

	//create the layer
	Vector3i currentLocation = minLocation.clone();
	for (int z=minLocation.getZ(); z<=maxLocation.getZ(); z++) {
	    currentLocation.setZ(z);
	    for (int x=minLocation.getX(); x<=maxLocation.getX(); x++) {
		currentLocation.setX(x);
                if(!DataStore.worldStateNode.getVoxelGrid().isVoxelAtLocation(currentLocation)) {
                    yLayer.attachChild(GrassBlock.createInstance(currentLocation));
                } else {
                    System.out.println("Already a voxel there, creator: "+currentLocation);
                }
	    }
	}

	return yLayer;
    }
}
